﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CommonDictionary.aspx.cs"
    Inherits="MagicBag.CRM.Web.Admin.CommonDictionary" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>通用字典管理</title>
    <style type="text/css">
        .DivCenter
        {
            margin-left: auto;
            margin-right: auto;
        }
        #SearchBar
        {
            margin-bottom: 5px;
        }
        
        #fm
        {
            margin: 0;
            padding: 10px 30px;
        }
        .ftitle
        {
            font-size: 14px;
            font-weight: bold;
            color: #666;
            padding: 5px 0;
            margin-bottom: 10px;
            border-bottom: 1px solid #ccc;
        }
        .fitem
        {
            margin-bottom: 5px;
        }
        .fitem label
        {
            display: inline-block;
            width: 80px;
        }
    </style>
    <link href="../Script/jquery-easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../Script/jquery-easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../Script/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="../Script/jquery-easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function qq(value, name) {
            // alert(value + ":" + name)
            if (name == '所有')
                name = '';
            var queryParams = $('#tt').datagrid('options').queryParams;
            queryParams.Category = name;
            queryParams.KeyWords = value;
            $('#tt').datagrid('options').queryParams = queryParams;
            $('#tt').datagrid('reload');
        }


        var url;
        function newDict() {
            $('#dlg').dialog('open').dialog('setTitle', '新增');
            $('#fm').form('clear');
            url = 'MagicBag.CRM.Service/CommonDictionaryService.crm?act=Insert';
        }
        function editDict() {
            var row = $('#tt').datagrid('getSelected');
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改');

                // $('#fm input[name="Category"]').combobox({
                $('#cc').combobox({
                    url: 'MagicBag.CRM.Service/CommonDictionaryService.crm?act=GetCategories',
                    valueField: 'Category',
                    textField: 'Category'
                });


                $('#fm').form('load', row);
                url = 'MagicBag.CRM.Service/CommonDictionaryService.crm?act=Update';
            }
        }
        function saveDict() {
            $('#fm').form('submit', {
                url: url,
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    var result = eval('(' + result + ')');
                    if (result.Success) {
                        $('#dlg').dialog('close'); 	// close the dialog
                        $('#tt').datagrid('reload'); // reload the user data
                    } else {
                        $.messager.alert("错误", result.Msg, "error");
                    }
                }
            });
        }
        function removeDict() {
            // var row = $('#tt').datagrid('getSelected');
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length > 0) {
                $.messager.confirm('确认', '您确定要删除这条记录吗?', function (r) {
                    if (r) {
                        $(rows).each(function () {
                            $.post('MagicBag.CRM.Service/CommonDictionaryService.crm?act=Delete', { id: $(this)[0].ID }, function (result) {
                                if (result.Success) {
                                    $('#tt').datagrid('reload'); // reload the user data
                                } else {
                                    $.messager.show({	// show error message
                                        title: 'Error',
                                        msg: result.Msg
                                    });
                                }
                            }, 'json');

                        });

                    }
                });
            }


        }


    </script>
</head>
<body>
    <div class="DivCenter" style="width: 100%; height: auto;">
        <!--搜索条-->
        <div id="SearchBar">
            <input id="SearchBox" class="easyui-searchbox" searcher="qq" menu="#SearchMenu" prompt="请输入"
                style="width: 300px" />
            <div id="SearchMenu" style="width: 120px">
                <div data-options="name:'',iconCls:'icon-ok'">
                    所有</div>
                <div data-options="name:'Category'">
                    分类</div>
                <div data-options="name:'Name'">
                    名称</div>
                <div data-options="name:'Value'">
                    值</div>
                <div data-options="name:'Description'">
                    描述</div>
            </div>
        </div>
        <!--明细-->
        <table id="tt" class="easyui-datagrid" url="MagicBag.CRM.Service/CommonDictionaryService.crm?act=GetCommonDictionaries"
            toolbar="#toolbar" singleselect="false" data-options="pagination:true, rownumbers:true,
        frozenColumns:[[  
            {field:'ck',checkbox:true}  
        ]]">
            <thead>
                <tr>
                    <th field="ID" width="100">
                        编号
                    </th>
                    <th field="Category" width="100">
                        分类
                    </th>
                    <th field="Name" width="100">
                        名称
                    </th>
                    <th field="Value" width="100">
                        值
                    </th>
                    <th field="Description" width="100">
                        描述
                    </th>
                    <th field="ParentID" width="100">
                        父ID
                    </th>
                </tr>
            </thead>
        </table>
        <!--工具条-->
        <div id="toolbar">
            <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newDict()">
                新增</a> <a href="#" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editDict()">
                    修改</a> <a href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="removeDict()">
                        删除</a>
        </div>
        <!--对话框-->
        <div id="dlg" class="easyui-dialog" style="width: 400px; height: 280px; padding: 10px 20px"
            closed="true" buttons="#dlg-buttons">
            <div class="ftitle">
                通用字典数据信息</div>
            <form id="fm" method="post" novalidate>
            <div class="fitem">
                <input name="ID" type="hidden" class="easyui-validatebox" readonly="readonly">
            </div>
            <div class="fitem">
                <label>
                    分类:</label>
                <input id="cc" name="Category" class="easyui-combobox" required="true">
                <%--<select id="cc" name="Category">
                <option></option>
                </select>--%>
            </div>
            <div class="fitem">
                <label>
                    名称:</label>
                <input name="Name" class="easyui-validatebox" required="true">
            </div>
            <div class="fitem">
                <label>
                    值:</label>
                <input name="Value" class="easyui-validatebox" required="true">
            </div>
            <div class="fitem">
                <label>
                    描述:</label>
                <input name="Description">
            </div>
            <div class="fitem">
                <input name="ParentID" type="hidden" class="easyui-validatebox" readonly="readonly">
            </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveDict()">保存</a>
            <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">
                取消</a>
        </div>
    </div>
</body>
</html>
